import router from '@/router'
import store from '@/store'
// 导入进度条
import Nprogress from 'nprogress'
const pageArr = ['/404', '/login']
import 'nprogress/nprogress.css'
router.beforeEach(async (to, from, next) => {
  Nprogress.start()
  if (store.getters.token) {
    if (to.path.toLowerCase() === '/login') {
      next('/')
    } else {
      // 验证个人用户信息
      if (!store.state.user.userInfo.userId) {
        await store.dispatch('user/getUserInfo')
      }
      next()
    }
  } else {
    if (pageArr.includes(to.path.toLowerCase())) {
      next()
    } else {
      // next('/login')
      // 处理回跳地址
      next(`/login?redirect=${encodeURIComponent(to.fullPath)}`)
    }
  }
  Nprogress.done()
})
// router.afterEach((to.from = {}))

// 陈莉丽的代码
// 导入路由和store
// import router from '@/router'
// import store from '@/store'

// router.beforeEach((to, form, next) => {
//   if (store.getters.token) {

//   }
// })
